package com.clarencezero.mylover.controller;

import com.clarencezero.mylover.common.QiNiuUtil;
import com.clarencezero.mylover.param.Result;
import com.clarencezero.mylover.param.entiry.ImageBean;
import com.clarencezero.mylover.service.ImageService;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.List;

@Controller
@RequestMapping("home")
public class ImageController {



    @Autowired
    private ImageService imageService;
    // 20180717 首页获取照片
    @GetMapping("firstPage")
    @ResponseBody
    public Result firstPage() {
        List<ImageBean> resultList =  imageService.firstPage();
        Result result = new Result();
        result.success("获取照片成功",resultList);
//        result.success();
        return result;
    }

    // 20180717 新增照片
    @PostMapping("aImage")
    @ResponseBody
    public Result aImage(@RequestBody ImageBean bean) {
        Result result = imageService.putImage(bean);
        return result;
    }

    // 20180718 上传照片到七牛云
    @PostMapping("putImage")
    @ResponseBody
    public Result putImage(@RequestParam("file")MultipartFile files,
                           HttpServletRequest request) {
        Result result = imageService.putImageByQiNiu(files, request);
        return result;
    }

}
